// 导入相应的 模块
//1.导入vue核心模块
import Vue from 'vue';

//2.导入根文件 App.vue 的vue对象
import App from './App.vue' ;

//3.将vue-router集合到这个项目中来
import vueRouter from 'vue-router';

//3.01 将vueRouter绑定到vue对象上
Vue.use(vueRouter);

//将vue-resource在vue中绑定，自动在vue对象实例上注入一个$http对象就可以使用ajax方法了

import vueResource from 'vue-resource' ;
Vue.use(vueResource);

//导入一个过滤时间的插件
import moment from 'moment';
Vue.filter('datefmt',function(input,fmtstring){
    return moment(input).format(fmtstring);
})
//导入图片缩略查看的插件
import VuePreview from 'vue-preview';
Vue.use(VuePreview);



//导入相应的组件
import home from './components/home.vue';
import newslist from './components/news/newslist.vue';
import mewsinfo from './components/news/newsinfo.vue';
// import component from './components/subcomment/comment.vue';
import photolist from './components/photo/photolist.vue';
import photoinfo from './components/photo/photoinfo.vue';
import videolist from './components/videos/videolist.vue';
import in_theater from './components/videos/in_theaters.vue';
import movedetails from './components/videos/videosinfo.vue';
import coming_soon from './components/videos/coming_soon.vue';
import top250 from './components/videos/top250.vue';
import goodslist from './components/goods/goodslist.vue';
import goodsinfo from './components/goods/goodsinfo.vue';
import goodscomment from './components/goods/goodscomment.vue';
import goodsimginfo from './components/goods/goodsimginfo.vue';
import shopcar from './components/shopcar/car.vue';
import login from './components/account/login.vue';
import userinfo from './components/account/userinfo.vue';

// 导入获取cookie的方法
import {getCookie} from './kikt/cookie.js';
//4定义路由规则

var router1 = new vueRouter({
    linkActiveClass:'mui-active',
    routes:[
        {path:'/',redirect:'/home'},
        {path:'/home',component:home},
        {path:'/news/newslist',component:newslist},
        {path:'/news/newsinfo/:id',component:mewsinfo},
        {path:'/photo/photolist',component:photolist},
        {path:'/photo/photoinfo/:id',component:photoinfo},
        {path:'/video/videolist',component:videolist},
        {path:'/in_theaters',component:in_theater},
        {path:'/movedetails/:id',component:movedetails},
        {path:'/coming_soon',component:coming_soon},
        {path:'/top250',component:top250},
        {path:'/goods/goodslist',component:goodslist},
        {path:'/goods/goodsinfo/:id',component:goodsinfo},
        {path:'/goods/goodscomment/:id',component:goodscomment},
        {path:'/goods/goodsimginfo/:id',component:goodsimginfo},
        {path:'/shopcar',component:shopcar},
        {path:'/login',component:login},
        {
			path: '/userinfo',
			component: userinfo,
			meta: {
				requireAuth: true,  // 添加该字段，表示进入这个路由是需要登录的
			},
			beforeEnter: (to, from, next) => {
				if (to.meta.requireAuth) {  // 判断该路由是否需要登录权限
					if (getCookie('session')) {  // 通过cookie获取当前的token是否存在
						next();
					}
					else {
						next({
							path: '/login',
							query: { redirect: to.fullPath }  // 将跳转的路由path作为参数，登录成功后跳转到该路由
						})
					}
				}
				else {
					next();
				}
			}
		}
    ]
})

//mint-ui 的使用
//5.01导入mint-ui的样式
import 'mint-ui/lib/style.min.css';
//5.02导入mint-ui 的组件包
import mintUi from 'mint-ui';
//5.03将mint-ui在vue中进行绑定
Vue.use(mintUi);

import '../statics/mui/css/mui.css';

import '../statics/css/site.css';


new Vue({
    el:'#app',
    router:router1,
    //render:function (creat) {return creat(App)}
    render:c=>c(App)
})

